package indzcraft.ui;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JTextArea;

public class Log extends JTextArea{
	
	private static final long serialVersionUID = 1L;

	public Log(){
		this.setEditable(true);
		this.setFocusable(true);
		this.setLineWrap(true);
		this.setWrapStyleWord(true);
	}
	
	public void append(String f){
		String time = getTime();
		String text = this.getText();
		if(text.equals(""))
			this.setText(time+f);
		else
			this.setText(this.getText()+"\n"+time+f);
		
		//scrollen
		setCaretPosition(this.getText().length());
		
	}
	
	private String getTime(){
		Calendar calendar = new GregorianCalendar();
		int min = calendar.get(Calendar.MINUTE);
		String min2 = ""+min;
		if(min < 10) min2 = "0"+min;
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		int sec = calendar.get(Calendar.SECOND);
		String sec2 = ""+sec;
		if(sec < 10) sec2 = "0"+sec;
		return "["+hour+":"+min2+":"+sec2+"] ";
	}
}
